package cn.sangyy.basic.raabbitmq.handler;

import cn.sangyy.basic.dto.SendEmailDto;
import cn.sangyy.basic.raabbitmq.config.RegisterNoticeRabbitmqConfig;
import cn.sangyy.basic.utils.SendEmail;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RegisterNoticeEmailReceiveHandler {

    @Autowired
    private SendEmail sendEmail;

    //监听email队列
    @RabbitListener(queues = {RegisterNoticeRabbitmqConfig.QUEUE_INFORM_EMAIL})
    public void receive_email(SendEmailDto sendEmailDto) {
        //使用email技术进行发送
        String imageUrl = sendEmailDto.getImageUrl();
        if(StringUtils.isNotBlank(imageUrl)){
            sendEmail.sendMime(sendEmailDto.getTopic(),sendEmailDto.getContext(),
                    sendEmailDto.getEmail(),imageUrl);
        }else {
            sendEmail.sendSimple(sendEmailDto.getTopic(),sendEmailDto.getContext(),sendEmailDto.getEmail());
        }

    }
}